/*
 * LDIR
 * 
 * LDIR, a GPS cartography application built for Let's Do It Romania eco 
 * campaign.
 * Copyright (C) 2010 Genera Software <office@generasoftware.com>
 * 
 * http://generasoftware.com/
 * 
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place, Suite 330, Boston, MA 02111-1307 USA
 */
#include <aknviewappui.h>
#include <eikmenub.h>
#include <avkon.hrh>
#include <akncontext.h>
#include <akntitle.h>
#include <stringloader.h>
#include <barsread.h>
#include <eikbtgpc.h>
#include <LDIR.rsg>
#include "LDIR.hrh"
#include "LDIRAboutView.h"
#include "LDIRAbout.h"

/**
 * First phase of Symbian two-phase construction. Should not contain any
 * code that could leave.
 */
CLDIRAboutView::CLDIRAboutView()
    {
    iLDIRAbout = NULL;
    }

/** 
 * The view's destructor removes the container from the control
 * stack and destroys it.
 */
CLDIRAboutView::~CLDIRAboutView()
    {
    delete iLDIRAbout;
    iLDIRAbout = NULL;
    }

/**
 * Symbian two-phase constructor.
 * This creates an instance then calls the second-phase constructor
 * without leaving the instance on the cleanup stack.
 * @return new instance of CLDIRAboutView
 */
CLDIRAboutView* CLDIRAboutView::NewL()
    {
    CLDIRAboutView* self = CLDIRAboutView::NewLC();
    CleanupStack::Pop( self );
    return self;
    }

/**
 * Symbian two-phase constructor.
 * This creates an instance, pushes it on the cleanup stack,
 * then calls the second-phase constructor.
 * @return new instance of CLDIRAboutView
 */
CLDIRAboutView* CLDIRAboutView::NewLC()
    {
    CLDIRAboutView* self = new ( ELeave ) CLDIRAboutView();
    CleanupStack::PushL( self );
    self->ConstructL();
    return self;
    }


/**
 * Second-phase constructor for view.  
 * Initialize contents from resource.
 */ 
void CLDIRAboutView::ConstructL()
    {
    BaseConstructL( R_LDIRABOUT_LDIRABOUT_VIEW );
    // add your own initialization code here
    
    }

/**
 * @return The UID for this view
 */
TUid CLDIRAboutView::Id() const
    {
    return TUid::Uid( ELDIRAboutViewId );
    }

/**
 * Handle a command for this view (override)
 * @param aCommand command id to be handled
 */
void CLDIRAboutView::HandleCommandL( TInt aCommand )
    {
    TBool commandHandled = EFalse;
    switch ( aCommand )
        {    // code to dispatch to the AknView's menu and CBA commands is generated here
		case EAknSoftkeyOk:
			AppUi()->HandleCommandL( ECmdMain );
			break;
        default:
            break;
        }
    
        
    if ( !commandHandled ) 
        {
    
        }
    }

/**
 *    Handles user actions during activation of the view, 
 *    such as initializing the content.
 */
void CLDIRAboutView::DoActivateL( 
        const TVwsViewId& /*aPrevViewId*/,
        TUid /*aCustomMessageId*/,
        const TDesC8& /*aCustomMessage*/ )
    {
    SetupStatusPaneL();
    
                
    if ( iLDIRAbout == NULL )
        {
        iLDIRAbout = CreateContainerL();
        iLDIRAbout->SetMopParent( this );
        AppUi()->AddToStackL( *this, iLDIRAbout );
        } 
    }

/**
 */
void CLDIRAboutView::DoDeactivate()
    {
    CleanupStatusPane();
    
    if ( iLDIRAbout != NULL )
        {
        AppUi()->RemoveFromViewStack( *this, iLDIRAbout );
        delete iLDIRAbout;
        iLDIRAbout = NULL;
        }
    }

/** 
 * Handle status pane size change for this view (override)
 */
void CLDIRAboutView::HandleStatusPaneSizeChange()
    {
    CAknView::HandleStatusPaneSizeChange();
    
    // this may fail, but we're not able to propagate exceptions here
    TVwsViewId view;
    AppUi()->GetActiveViewId( view );
    if ( view.iViewUid == Id() )
        {
        TInt result;
        TRAP( result, SetupStatusPaneL() );
        }
    }

// [[[ begin generated function: do not modify
void CLDIRAboutView::SetupStatusPaneL()
    {
    // reset the context pane
    TUid contextPaneUid = TUid::Uid( EEikStatusPaneUidContext );
    CEikStatusPaneBase::TPaneCapabilities subPaneContext = 
        StatusPane()->PaneCapabilities( contextPaneUid );
    if ( subPaneContext.IsPresent() && subPaneContext.IsAppOwned() )
        {
        CAknContextPane* context = static_cast< CAknContextPane* > ( 
            StatusPane()->ControlL( contextPaneUid ) );
        context->SetPictureToDefaultL();
        }
    
    // setup the title pane
    TUid titlePaneUid = TUid::Uid( EEikStatusPaneUidTitle );
    CEikStatusPaneBase::TPaneCapabilities subPaneTitle = 
        StatusPane()->PaneCapabilities( titlePaneUid );
    if ( subPaneTitle.IsPresent() && subPaneTitle.IsAppOwned() )
        {
        CAknTitlePane* title = static_cast< CAknTitlePane* >( 
            StatusPane()->ControlL( titlePaneUid ) );
        TResourceReader reader;
        iEikonEnv->CreateResourceReaderLC( reader, R_LDIRABOUT_TITLE_RESOURCE );
        title->SetFromResourceL( reader );
        CleanupStack::PopAndDestroy(); // reader internal state
        }
                
    }

void CLDIRAboutView::CleanupStatusPane()
    {
    }


/**
 *    Creates the top-level container for the view.  You may modify this method's
 *    contents and the CLDIRAbout::NewL() signature as needed to initialize the
 *    container, but the signature for this method is fixed.
 *    @return new initialized instance of CLDIRAbout
 */
CLDIRAbout* CLDIRAboutView::CreateContainerL()
    {
    return CLDIRAbout::NewL( ClientRect(), NULL, this );
    }

